<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Contact extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Default function
     */
    public function index()
    {
        
    }
    public function send(){
        $this->disable_view();
        global $site_info;
        $post = $this->input->post(null);
        $data['subject'] = $post['subject'];
        $data['email']   = $post['email'];
        $data['emailto'] =$site_info['email_address'];
        $data['name'] =$post['name'];
        $data['content']=$post['content'];
        $this->_send_mail('customer-contact',$data);
        _set_success_message('Đã gửi.');
        redirect('contact');
        
    }
    public function _send_mail($type,$data){
        $this->disable_view();
        $config['protocol']='smtp';  
        $config['smtp_host']='ssl://smtp.gmail.com';  
        $config['smtp_port']='465';  
        $config['smtp_timeout']='3000';  
        $config['smtp_user']='harry88pham@gmail.com';  
        $config['smtp_pass']='05111988';  
        $config['charset']='utf-8';  
        $config['newline']="\r\n"; 
        $config['mailtype'] = 'html'; 
        $config['wordwrap'] = FALSE;
        
        $this->load->library('email',$config);
        $this->email->from($data['email']);
              $this->email->to($data['emailto']);

              $this->email->subject($data['subject']);
              $this->email->message($this->load->view('layouts/email/'.$type.'-html',$data,true));  
        $this->email->send();
    }

    
}